home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.infosystems.www.servers.unix,comp.lang.c
- Path: news.draper.com!nntp
- From: Brandon Shalton <bshalton@draper.com>
- Subject: Opening a binary file.... (dealing with content-type & WWW)
- Content-Type: text/plain; charset=us-ascii
- Message-ID: <317351DE.E7E@draper.com>
- Sender: nntp@draper.com (NNTP Master)
- Nntp-Posting-Host: bam3106cx.draper.com
- Content-Transfer-Encoding: 7bit
- Organization: Draper Laboratory
- Mime-Version: 1.0
- Date: Tue, 16 Apr 1996 07:53:02 GMT
- X-Mailer: Mozilla 2.0 (Macintosh; I; 68K)
-
- Hello,
-
- I am trying to establish content-types (mime) based upon the header
- of the file, rather than relying on the file extension. I have
- instances where file extensions overlap...ex. .doc (microsoft word),
- .doc (ascii text document).
-
- To be able to set the content-type correctly to launch the
- appropriate viewer, I am modifying the "file" command to be able to
- look up by magic types. I have coded the magic type
- application/msword in the magic file. The modified file program
- would then open the desired file, and stream it out to the user.
-
- Originally I was doing a fork/exec and basically cat'ting the file.
- This works under Solaris, but for some reason, it doesn't work on
- SunOS. Plus, I have seen hung processes.
-
- I have decided to take out the fork/exec and replace it with a
- simple open file, read contents, send to browser routine.
-
- This is my first cut...
-
-
-
- fd2=open(entries[0].val,O_RDONLY);
- for(;;)
- {
- if( read(fd2, tbuf, 1) <=0 ) exit(1);
- printf("%s", tbuf);
- }
-
-
- This snippet does read the file, and sends the file out..but when
- viewed from Microsoft Word, the file comes through as text, showing
- the control characters at the header of the file. It looks like
- ascii is being sent out rather than binary.
-
- I have also tried:
-
-
-
- fin2=fopen(entries[0].val,"rb");
- while( ch=fgetc(fin2) != EOF )
- printf("%c", ch);
- exit(1);
-
- and have gotten the same type of result.
-
- Any pointers would be greatly appreciated...
-
- -Brandon
-
- ** Web Developer
- ** Draper Laborator
- ** Cambridge, MA USA
- **
- ** bshalton@draper.com
-